package com.taxi.apipassenger.controller;


import com.taxi.apipassenger.request.CheckVerificationCodeDTO;
import com.taxi.apipassenger.request.SendVerificationCodeDTO;
import com.taxi.apipassenger.service.VerificationCodeService;
import com.taxi.common.dto.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author ruomengjiang
 * @Date 2022/6/12
 * @Description : online-taxi
 * @Version: 1.0
 */
@RestController
public class VerificationCodeController {

    @Autowired
    private VerificationCodeService verificationCodeService;

    /**
     * 发送验证码
     * @param sendVerificationCodeDTO
     * @return
     */
    @PostMapping("/verification-code")
    public ResponseResult verificationCode(@Validated @RequestBody SendVerificationCodeDTO sendVerificationCodeDTO){

        String passengerPhone = sendVerificationCodeDTO.getPassengerPhone();
        return verificationCodeService.generatorCode(passengerPhone);
    }

    /**
     * 校验验证码
     * @param checkVerificationCodeDTO
     * @return
     */
    @PostMapping("/verification-code-check")
    public ResponseResult checkVerificationCode(@Validated @RequestBody CheckVerificationCodeDTO checkVerificationCodeDTO){

        String passengerPhone = checkVerificationCodeDTO.getPassengerPhone();
        String checkVerificationCode = checkVerificationCodeDTO.getVerificationCode();

        //System.out.println("手机号"+passengerPhone+",验证码："+checkVerificationCode);
        return verificationCodeService.checkCode(passengerPhone,checkVerificationCode);
    }

}
